package com.example.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@ComponentScan(basePackages = {"com.example.demo.*"})
@MapperScan("com.example.demo.person.mapper")
public class DemoApplication {

    private static Logger log = LoggerFactory.getLogger(DemoApplication.class);

    public static void main(String[] args) throws UnknownHostException {
        log.info("Easy Excel Cover Start>>>>>");
        // 获取ip
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        // 获取服务配置，name、port、以及全局服务路径
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        ConfigurableEnvironment environment = context.getEnvironment();
        String appName = environment.getProperty("spring.application.name");
        String appPort = environment.getProperty("server.port");
        String appPath = environment.getProperty("server.servlet.context-path");
        log.info("Application " + appName + " is running!");
        log.info("Local access url: http://localhost:" + appPort + appPath);
        log.info("External access url: http://" + hostAddress + ":" + appPort + appPath);
    }

}
